package com.itwn.email.producer.send;

import com.itwn.email.producer.a_simple.SimpleProducer;
import com.itwn.email.producer.c_fanout.FanoutProducer;
import com.itwn.email.producer.d_direct.DirectConfig;
import com.itwn.email.producer.d_direct.DirectProducer;
import com.itwn.email.producer.e_topic.TopicConfig;
import com.itwn.email.producer.e_topic.TopicProducer;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class App {

    // 简单模式 - 消息生产者
    @Autowired
    private SimpleProducer simpleProducer;
    // 发布订阅模式 - 消息生产者
    @Autowired
    private FanoutProducer fanoutProducer;
    // 路由模式 - 消息生产者
    @Autowired
    private DirectProducer directProducer;
    // 通配符模式
    @Autowired
    private TopicProducer topicProducer;

    // 发消息
    @Test
    public void send() {
        for (int i = 0; i < 10; i++) {
            simpleProducer.send("Hello,小兔子！" + i);
        }
    }

    @Test
    public void sendFanout() {
        fanoutProducer.send("发送消息，交换机类型：fanout");
    }

    @Test
    public void sendDirect() {
        directProducer.send(DirectConfig.DIRECT_EXCHANGE, "ab", "发给第一个队列，路由key：a");
    }

    @Test
    public void sendTopic() {
        topicProducer.send(TopicConfig.TOPIC_EXCHANGE, "china.news", "发给第2个队列,路由china.news");
    }
}
